﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>资产库存管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.8.18/dist/css/layui.min.css">
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <div class="layui-col-md12">
                <!-- 搜索筛选区 -->
                <div class="layui-card">
                    <div class="layui-card-header">资产库存查询</div>
                    <div class="layui-card-body">
                        <form class="layui-form" id="searchForm">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">资产名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="assetName" autocomplete="off" class="layui-input" placeholder="请输入资产名称">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button type="button" class="layui-btn layui-btn-normal" id="searchBtn">
                                        <i class="layui-icon">&#xe615;</i>搜索
                                    </button>
                                    <button type="button" class="layui-btn layui-btn-primary" id="resetBtn">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

                <!-- 表格区 -->
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-form"></i>
                        资产库存列表
                        <span class="layui-badge layui-bg-orange" id="totalCount">0</span>
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-hide" id="assetInventoryTable" lay-filter="assetInventoryTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/layui@2.8.18/dist/layui.min.js"></script>
    <script>
        layui.use(['table', 'form'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;

            // 初始化表格
            var tableIns = table.render({
                elem: '#assetInventoryTable',
                url: '/AssetInventory/GetAssetInventoryList',
                method: 'get',
                page: true,
                limit: 10,
                limits: [10, 20, 50],
                loading: true,
                text: {
                    none: '暂无相关数据'
                },
                cols: [[
                    { type: 'numbers', title: '序号', width: 80 },
                    { field: 'AssetName', title: '资产名称', width: 180 },
                    { field: 'AssetModel', title: '规格型号', width: 120 },
                    { field: 'AssetCompany', title: '单位', width: 100 },
                    { field: 'TotalPut', title: '总入库数量', width: 120, sort: true },
                    { field: 'TotalUsed', title: '已领取数量', width: 120, sort: true },
                    {
                        field: 'TotalRemain',
                        title: '剩余库存',
                        width: 120,
                        sort: true,
                        templet: function (d) {
                            var color = d.TotalRemain > 0 ? 'green' : 'red';
                            return '<span style="color: ' + color + '; font-weight: bold;">' + d.TotalRemain + '</span>';
                        }
                    }
                ]],
                parseData: function (res) {
                    if (res.code === 0) {
                        $('#totalCount').text(res.count || 0);
                    }
                    return {
                        "code": res.code || 0,
                        "msg": res.msg || "",
                        "count": res.count || 0,
                        "data": res.data || []
                    };
                }
            });

            // 搜索功能
            $('#searchBtn').on('click', function () {
                var formData = form.val('searchForm');
                tableIns.reload({
                    where: formData,
                    page: { curr: 1 }
                });
            });

            // 重置功能
            $('#resetBtn').on('click', function () {
                form.val('searchForm', {
                    assetName: ''
                });
                form.render();
                tableIns.reload({
                    where: {},
                    page: { curr: 1 }
                });
            });
        });
    </script>
</body>
</html>